<?php

use yii\db\Migration;

/**
 * Class m221113_145020_rbac_contract_purpose
 */
class m221113_145020_rbac_contract_purpose extends Migration
{       
    /**
    * {@inheritdoc}
    */
   public function safeUp()
   {
       $auth = Yii::$app->authManager;

       $permissionCreate = $auth->createPermission('createContractPurpose');
       $auth->add($permissionCreate);

       $permissionUpdate = $auth->createPermission('updateContractPurpose');
       $auth->add($permissionUpdate);

       $permissionDelete = $auth->createPermission('deleteContractPurpose');
       $auth->add($permissionDelete);

       $permissionBrowse = $auth->createPermission('browseContractPurpose');
       $auth->add($permissionBrowse);

       $userRole = $auth->createRole('contractPurposeUser');
       $auth->add($userRole);

       $managerRole = $auth->createRole('contractPurposeManager');
       $auth->add($managerRole);

       $auth->addChild($userRole, $permissionBrowse);

       $auth->addChild($managerRole, $permissionCreate);
       $auth->addChild($managerRole, $permissionUpdate);
       $auth->addChild($managerRole, $permissionDelete);
       $auth->addChild($managerRole, $permissionBrowse);
   }

   /**
    * {@inheritdoc}
    */
   public function safeDown()
   {
       $auth = Yii::$app->authManager;

       $auth->remove($auth->getPermission('createContractPurpose'));
       $auth->remove($auth->getPermission('updateContractPurpose'));
       $auth->remove($auth->getPermission('deleteContractPurpose'));
       $auth->remove($auth->getPermission('browseContractPurpose'));
       $auth->remove($auth->getRole('contractPurposeUser'));
       $auth->remove($auth->getRole('contractPurposeManager'));
   }
}
